using System;
using System.Collections.Generic;
using System.Text;
using DataTools;
using DataTools.PagingUtils;
using ObjectLayer;

namespace AccessLayer
{
	public class dim_unitDAO
{
		public static List<dim_unitBO> GetAll()
		{
            ConnInfo.Db = "VNPT_Bsc";
			return CBO.FillCollection<dim_unitBO>(DataProvider.getInstance().getAll(TableName.dim_unit, PagingHelper.CreateOrder(new OrderObject(dim_unitTable.code, SortOrder.Desc))));
		}
		static object _Clock = new object();
		public static List<dim_unitBO> GetAllC()
		{
            ConnInfo.Db = "VNPT_Bsc";
			List<dim_unitBO> list = new List<dim_unitBO>();
			if(DataCache.GetCache(CacheName.dim_unit) == null)
			{
				lock (_Clock)
				{
					if (DataCache.GetCache(CacheName.dim_unit) != null)
					{
						list = (List<dim_unitBO>)DataCache.GetCache(CacheName.dim_unit);
					}
					else
					{
			list = CBO.FillCollection<dim_unitBO>(DataProvider.getInstance().getAll(TableName.dim_unit, PagingHelper.CreateOrder(new OrderObject(dim_unitTable.code, SortOrder.Desc))));
						DataCache.SetCache(CacheName.dim_unit, list);
					}
				}
			}
			else
			{
					list = (List<dim_unitBO>)DataCache.GetCache(CacheName.dim_unit);
			}
		return list;
		}
		public static int InsertUpdateDelete(dim_unitBO dim_unit, ProviderAction action)
		{
            ConnInfo.Db = "VNPT_Bsc";
			int rs = DataProvider.getInstance().InsertUpdateDelete(action, StoreProcedureName.InsertUpdateDelete_dim_unit, "@" + dim_unitTable.code, dim_unit.code,dim_unit.name,dim_unit.slug, DataTools.ConvertType.ToInt(action));
			if (rs != -1)
			{
				DataCache.RemoveCache(CacheName.dim_unit);
			}
			return rs;
		}
		
	}
}